package com.refactor.practice;

import java.math.BigDecimal;

public class Rental {
	private Movie _movie;

	private int _dayRented;

	private BigDecimal _totalPrice; // 影片租赁价格

	private int _points; // 租赁影片获取的积分

	public Rental(Movie movie, int dayRented) {
		_movie = movie;
		_dayRented = dayRented;
		this.countPrice();
		this.countPoints();
	}

	/**
	 * 计算影片的租赁价格
	 */
	private void countPrice(){
		BigDecimal amount = new BigDecimal(0).setScale(1);
		switch (_movie.getPriceCode()) {
			case Movie.REGULAR:
				amount = amount.add(new BigDecimal(2));
				if (_dayRented > 2) {
					amount = amount.add(new BigDecimal((_dayRented - 2) * 1.5));
				}
				break;
			case Movie.NEW_RELEASE:
				amount = amount.add(new BigDecimal(_dayRented * 3));
				break;
			case Movie.CHILDRENS:
				amount = amount.add(new BigDecimal(1.5));
				if (_dayRented > 2) {
					amount = amount.add(new BigDecimal((_dayRented - 3) * 1.5));
				}
				break;
			case Movie.VIP_MOVIES:
				amount = amount.add(new BigDecimal(10));
				if (_dayRented > 2) {
					amount = amount.add(new BigDecimal((_dayRented - 2) * 3));
				}
		}
		_totalPrice = amount;
	}

	/**
	 * 计算租赁影片能获取的积分
	 */
	private void countPoints(){
		int point = 0;
		switch (_movie.getPriceCode()) {
			case Movie.VIP_MOVIES:
				point = 3;
				break;
			case Movie.NEW_RELEASE:
				point = 2;
				break;
			default:
				point = 1;
				break;
		}
		_points = point;
	}

	public Movie getMovie() {
		return _movie;
	}

	public int getDayRented() {
		return _dayRented;
	}

	public BigDecimal getTotalPrice() {
		return _totalPrice;
	}

	public int getPoints() {
		return _points;
	}
}
